package com.e3.template.tgf;

import com.e3.template.model.TGFTreeModel;

public abstract class TGFHelper<D extends TGFTreeModel> extends GFHelper<D>{

	public D createRootModel(){
		D model = createModelInstance();
		model.setId(0L);
		model.set(getCodeFieldName(), "0");
		model.setHasChildren(true);
		return model;
	}
	
	public boolean isRootModel(D model){
		if(model==null){
			return false;
		}
		return "0".equals(model.get(getCodeFieldName()));
	}
	
	/**
	 * 是否是最高层。
	 * 
	 * @param model
	 * @return
	 */
	public boolean isTopModel(D model){
		if(model==null){
			return false;
		}
		return "0".equals(model.getParentId());
	}
	
	public abstract String getCodeFieldName();
}
